-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(gas_price_service): initialize v1 metadata #2288
Conversation
pub struct V1Metadata { | ||
// Execution | ||
/// The gas price (scaled by the `gas_price_factor`) to cover the execution of the next block | ||
pub new_scaled_exec_price: u64, | ||
/// The lowest the algorithm allows the exec gas price to go | ||
pub min_exec_gas_price: u64, | ||
/// The Percentage the execution gas price will change in a single block, either increase or decrease | ||
/// based on the fullness of the last L2 block. Using `u16` because it can go above 100% and | ||
/// possibly over 255% | ||
pub exec_gas_price_change_percent: u16, | ||
/// The height of the next L2 block | ||
pub l2_block_height: u32, | ||
/// The threshold of gas usage above and below which the gas price will increase or decrease | ||
/// This is a percentage of the total capacity of the L2 block | ||
pub l2_block_fullness_threshold_percent: ClampedPercentage, | ||
// DA | ||
/// The gas price (scaled by the `gas_price_factor`) to cover the DA commitment of the next block | ||
pub new_scaled_da_gas_price: u64, | ||
|
||
/// Scale factor for the gas price. | ||
pub gas_price_factor: NonZeroU64, | ||
/// The lowest the algorithm allows the da gas price to go | ||
pub min_da_gas_price: u64, | ||
/// The maximum percentage that the DA portion of the gas price can change in a single block | ||
/// Using `u16` because it can go above 100% and possibly over 255% | ||
pub max_da_gas_price_change_percent: u16, | ||
/// The cumulative reward from the DA portion of the gas price | ||
pub total_da_rewards_excess: u128, | ||
/// The height of the last L2 block recorded on the DA chain | ||
pub da_recorded_block_height: u32, | ||
/// The cumulative cost of recording L2 blocks on the DA chain as of the last recorded block | ||
pub latest_known_total_da_cost_excess: u128, | ||
/// The predicted cost of recording L2 blocks on the DA chain as of the last L2 block | ||
/// (This value is added on top of the `latest_known_total_da_cost` if the L2 height is higher) | ||
pub projected_total_da_cost: u128, | ||
/// The P component of the PID control for the DA gas price | ||
pub da_p_component: i64, | ||
/// The D component of the PID control for the DA gas price | ||
pub da_d_component: i64, | ||
/// The last profit | ||
pub last_profit: i128, | ||
/// The profit before last | ||
pub second_to_last_profit: i128, | ||
/// The latest known cost per byte for recording blocks on the DA chain | ||
pub latest_da_cost_per_byte: u128, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc: @MitchTurner, if you can describe which ones we need and which ones are just being used/mutated internally by the AlgorithmUpdater
please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Same as with V0, but we need to multiply it by the `gas_price_factor`. A constructor would help a lot here :)
pub new_scaled_exec_price: u64,
/// Same as with V0 (this isn't scaled, I double checked.
pub min_exec_gas_price: u64,
/// Same as V0
pub exec_gas_price_change_percent: u16,
/// Should be confirmed with metadata sync
pub l2_block_height: u32,
/// Same as V0
pub l2_block_fullness_threshold_percent: ClampedPercentage,
/// Should be defined in config. Should be multiplied by `gas_price_factor`. Again, constructor would be good.
pub new_scaled_da_gas_price: u64,
/// `100` should be good and we can hardcode it if we want.
pub gas_price_factor: NonZeroU64,
/// Should be set with config
pub min_da_gas_price: u64,
/// Should be set with config
pub max_da_gas_price_change_percent: u16,
/// Zero on start (saved in Metadata)
pub total_da_rewards_excess: u128,
/// Currently the correct value is required here on startup, i.e. we should know what we expect next from the committer and do the block before that. BUT I think we should allow it to start with None. (saved in Metadata)
pub da_recorded_block_height: u32,
/// Zero on start (saved in Metadata)
pub latest_known_total_da_cost_excess: u128,
/// Zero on start (saved in Metadata)
pub projected_total_da_cost: u128,
/// Set with Config
pub da_p_component: i64,
/// Set with Config
pub da_d_component: i64,
/// Zero on start (saved in Metadata)
pub last_profit: i128,
/// Zero on start (saved in Metadata)
pub second_to_last_profit: i128,
/// Zero on start (saved in Metadata)
pub latest_da_cost_per_byte: u128,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is super useful, making the required changes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lmk if bcb1fd3 makes sense, then i will open the PR for review from others :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized that I put (saved in Metadata)
on a few of them, but there are others that I missed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the action here? should I change the metadata?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bump @MitchTurner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry. Missed this. I just updated.
I have the rest of the code for |
bcb1fd3
to
cfb7b1b
Compare
cfb7b1b
to
298de5f
Compare
So. I wanted to remove the unneeded fields from the metadatas, this let me to modifying how the tests work... which led me to fixing some of the tests. I don't know if we want to keep that in this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks mostly good to me. There are a few dangling todos that need to be addressed. Beyond that I just have a few questions and suggestions.
// TODO: we need to alter fuel-core configuration to include versioned config, after which | ||
// we can directly pass it into the constructor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we do it now or create a follow-up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm removing the TODO. We need to decide if we are going to specify like that or just switch it to the new version and never support the old version. We're tracking the work regardless.
pub starting_gas_price: u64, | ||
pub gas_price_change_percent: u64, | ||
pub gas_price_threshold_percent: u64, | ||
pub enum VersionSpecificConfig { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'd prefer the old name here GasPriceServiceConfig
. The fact that it's versioned is clear enough given the V0
and V1
variants, and any code which doesn't match on the version variants shouldn't have to care if it's versioned or not.
pub enum VersionSpecificConfig { | |
pub enum GasPriceServiceConfig |
Self::V1(metadata) | ||
} | ||
|
||
/// Extract V0MetadataInitializer if it is of V0 version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's V0MetadataInitializer
?
@@ -91,27 +116,28 @@ impl MetadataStorage for ErroringMetadata { | |||
} | |||
} | |||
|
|||
fn arb_config() -> V0AlgorithmConfig { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: While we already use the arb
abbreviation for the arb_metadata()
, I find it easier to read if we spell out the full word:
fn arb_config() -> V0AlgorithmConfig { | |
fn arbitrary_config() -> V0AlgorithmConfig { |
pub struct GasPriceServiceConfig { | ||
version_specific_config: VersionSpecificConfig, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of wrapping VersionSpecificCoinfig
here as opposed to just having a single enum?
pub enum GasPriceServiceConfig {
V0(...)
V1(...)
}
pub fn new_v1(metadata: V1AlgorithmConfig) -> Self { | ||
Self::V1(metadata) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'd complement these constructors with with From<VXAlgorithmConfig>
implementations.
// GasPriceData + Modifiable + KeyValueInspect<Column = GasPriceColumn> | ||
impl GasPriceData for FakeGasPriceDb { | ||
fn latest_height(&self) -> Option<BlockHeight> { | ||
todo!() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dangling todo. Shuld we remove this function or when is it to be implemented?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's fine. It just doesn't get called in the scope of any of these tests, but we're still required to pass something that implements that trait.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can change to unimplemented
if that's better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah then unimplemented
conveys the intention better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice first step towards new gas price 🚀 WP. LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating! 🙏
Note
This is PR 1/n in introducing
GasPriceServiceV1
which links tov1
of thegas-price-algorithm
. This PR is mainly used to start the discussion around v1 metadata and the fields we need.Linked Issues/PRs
fixes #2286
Description
V1Metadata
that will be stored alongV0Metadata
wrapped within theUpdaterMetadata
struct.v0
=>v1
should be possibleAlgorithmUpdaterV1
fromV1Metadata
Bonus:
initialize_algorithm
to test theUninitializedTask
instead--a public interface.Checklist
Before requesting review
After merging, notify other teams
[Add or remove entries as needed]